from django.db import models

from apps.login.models import UserInfo
from apps.publish.models import PublishModel

# 访问记录模型类
class ViewerRecordModel(models.Model):
    user = models.ForeignKey(UserInfo,verbose_name="用户",on_delete=models.CASCADE)
    article = models.ForeignKey(PublishModel,verbose_name="访问的文章",on_delete=models.CASCADE)

    class Meta:
        db_table = "Viewer"
        verbose_name = "访客记录"
        verbose_name_plural = verbose_name


# 评论表模型类
class CommentRecordModel(models.Model):
    article = models.ForeignKey(PublishModel,verbose_name="文章",on_delete=models.CASCADE)
    content = models.CharField(verbose_name="评论内容",max_length=255)
    user = models.ForeignKey(UserInfo,verbose_name="发布者",on_delete=models.CASCADE)
    createTime = models.DateTimeField(verbose_name="发布时间",auto_now_add=True)

    reply = models.ForeignKey(verbose_name="回复",to="self",on_delete=models.CASCADE,null=True,blank=True,related_name="replys")
    depth = models.PositiveIntegerField(verbose_name="评论层级",default=1)
    root = models.ForeignKey(verbose_name="根评论",to="self",on_delete=models.CASCADE,null=True,blank=True,related_name="roots")

    favor_count = models.PositiveIntegerField(verbose_name="赞数",default=0)

    class Meta:
        db_table = "CommentRecord"
        verbose_name = "用户评论表"
        verbose_name_plural = verbose_name


# 赞表模型类
class FavorRecordModel(models.Model):
    article = models.ForeignKey(PublishModel,verbose_name="赞的文章",on_delete=models.CASCADE)
    user = models.ForeignKey(UserInfo,verbose_name="点赞用户",on_delete=models.CASCADE)

    class Meta:
        db_table = "FavorRecordModel"
        verbose_name = "文章点赞"
        verbose_name_plural = verbose_name